<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      http-equiv="X-UA-Compatible"
      content="IE=edge"
    />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0"
    />
    <title>Document</title>
    <link
      rel="stylesheet"
      href=""
    />
    <style>
      body,
      html {
        margin: 0;
        padding: 0;
      }
      .box {
        width: 800px;
        height: 600px;
        margin: 50px auto;
      }

      .tabs {
        height: 100px;
        display: flex;
        background-color: #fff;
      }

      .tabs .tab_item {
        flex: 1;
        line-height: 100px;
        text-align: center;
        background-color: #ccc;
        color: #000;
      }

      .tabs .tab_item.active {
        background-color: #ff6700;
        color: #fff;
      }

      .mains {
        width: 100%;
        height: 500px;
      }

      .main_item {
        width: 100%;
        height: 100%;
        display: none;
        text-align: center;
        line-height: 500px;
        font-size: 50px;
        font-weight: 600;
        background-color: aqua;
      }

      .main_item:nth-child(2) {
        background-color: burlywood;
      }
      .main_item:nth-child(3) {
        background-color: chartreuse;
      }

      .main_item.active {
        display: block;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="tabs">
        <div
          data-index="0"
          class="tab_item active"
        >
          选项一
        </div>
        <div
          data-index="1"
          class="tab_item"
        >
          选项二
        </div>
        <div
          data-index="2"
          class="tab_item"
        >
          选项三
        </div>
      </div>
      <div class="mains">
        <div class="main_item active">内容一</div>
        <div class="main_item">内容二</div>
        <div class="main_item">内容三</div>
      </div>
    </div>
    <script>
      let activeIndex = 0
      const tabs = Array.from(document.querySelector('.tabs').children)
      const mains = Array.from(document.querySelector('.mains').children)

      tabs.forEach((el) => {
        el.addEventListener('click', () => {
          document.querySelectorAll('.active').forEach((el) => {
            el.classList.remove('active')
          })
          el.classList.add('active')
          mains[el.dataset.index].classList.add('active')
        })
      })
    </script>
  </body>
</html>
